<?php
// application/forms/UserLogin.php
/**
 * Form_UserLogin
 *
 * This form is created in dojo style
 *
 * @author Adam Pilacki
 * @version 1.0.0
 */
final class Form_UserLogin extends Zend_Dojo_Form
{
    public final function init()
    {
        $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/user/login')
            ->setMethod(Zend_Form::METHOD_POST)
            ->setName('UserLogin')
//            ->setEnctype(Zend_Form::ENCTYPE_MULTIPART)
//            ->setAttrib('onSubmit', 'return validate(this)')
            ->setIsArray(true)
        ;

        $this->getView()->dojo()
            ->requireModule('dijit.form.Form')
            ->requireModule('dijit.form.Button')
            ->requireModule('dijit.form.ValidationTextBox')
            ->requireModule('dojox.validate.regexp')
        ;

        $translator = Zend_Registry::get('translator');

//        Zend_Form::setTranslator(Zend_Registry::get('translator'));

        $regexp = '[a-zA-Z0-9_-]+';

        /* login field */
        $login = new Zend_Dojo_Form_Element_ValidationTextBox(
            'login',
            array(
                'id'             => 'userLoginLogin',
                'label'          => $translator->translate('Login:'),
                'required'       => true,
                'invalidMessage' => $translator->translate('Wykryto niewłaściwe znaki.'),
                'formatLength'   => 'long',
                'regExp'         => $regexp,
            )
        );

        /* password field */
        $password = new Zend_Dojo_Form_Element_PasswordTextBox(
            'password',
            array(
                'id'             => 'userLoginPasssword',
                'label'          => $translator->translate('Hasło:'),
                'required'       => true,
                'invalidMessage' => $translator->translate('Wykryto niewłaściwe znaki.'),
                'formatLength'   => 'long',
                'regExp'         => $regexp,
            )
        );

        // Submit button
        $submit = new Zend_Dojo_Form_Element_SubmitButton('submit');
        $submit->setDijitParam('label', $translator->translate('Zaloguj się'))
            ->setLabel($translator->translate('Zaloguj się'))
        ;

        // Add elements to form
        $this->addElements(array($login, $password, $submit));
    }
}